//
//  LBVintageHighFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 3/29/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBVintageHighFilter.h"
#include "LBOverlayTextureFilter.h"
#include "LBExclusionColorFilter.h"
#include "LBSoftlightColorFilter.h"
#include "LBSoftlightTextureFilter.h"
#include "LBUtils.h"
#include "LBTexture.h"
#include "LBFramebuffer.h"

LBVintageHighFilter::LBVintageHighFilter(){
    overlayGradient = new LBOverlayTextureFilter();
    overlayGradient->setOpactiy(0.2);
    
    exclusionBlackBlue = new LBExclusionColorFilter();
    exclusionBlackBlue->setOpactiy(0.6);
    exclusionBlackBlue->setColor(0.027, 0.0, 0.259);
    
    softlightOrange = new LBSoftlightColorFilter();
    softlightOrange->setColor(0.871, 0.608, 0.51);
    softlightOrange->setOpactiy(0.1);
    
    softlightPink = new LBSoftlightColorFilter();
    softlightPink->setColor(1.0, 0.82, 0.922);
    softlightPink->setOpactiy(0.06);
    
    exclusionBlackBlue2 = new LBExclusionColorFilter();
    exclusionBlackBlue2->setColor(0.027, 0.0, 0.259);
    exclusionBlackBlue2->setOpactiy(0.6);
    
    softlightOrigin = new LBSoftlightTextureFilter();
    softlightOrigin->setOpactiy(0.2);
    
    overlayGradient->addTarget(exclusionBlackBlue)->addTarget(softlightOrange)->addTarget(softlightPink)->addTarget(exclusionBlackBlue2)->addTarget(softlightOrigin);
    firstFilter = overlayGradient;
}

LBVintageHighFilter::~LBVintageHighFilter(){
    outputTexture = 0;
    DELETE_SAFELY(overlayGradient);
    DELETE_SAFELY(exclusionBlackBlue2);
    DELETE_SAFELY(exclusionBlackBlue);
    DELETE_SAFELY(softlightOrigin);
    DELETE_SAFELY(softlightOrange);
    DELETE_SAFELY(softlightPink);
}

void LBVintageHighFilter::setTexture(LBTexture* texture){
    overlayGradient->setTexture(texture);
    softlightOrigin->setBlendTexture(texture);
    outputTexture = overlayGradient->getFinalOutputTexture();
    
    if(targetFilter != 0){
        targetFilter->setTexture(outputTexture);
    }
}

void LBVintageHighFilter::setBlendTexture(LBTexture* blendTexture){
    overlayGradient->setBlendTexture(blendTexture);
}